package day_2022_9_to_12.Day;

/**
 * @author haomin
 * @date 2022/10/19 16:03
 **/

public class Day47_2_Num222_CountNodes {
    class Solution {
        int ans = 0;
        public int countNodes(TreeNode root) {
            preOrder(root);
            return ans;
        }
        private void preOrder(TreeNode root){
            if(root == null) return;
            ans++;
            preOrder(root.left);
            preOrder(root.right);
        }
    }
    class Solution2 {
        public int countNodes(TreeNode root) {
            if(root == null) return 0;
            int l = depth(root.left);
            int r = depth(root.right);
            System.out.println(l + " "+r);
            if(l == r) return (1 << l) + countNodes(root.right);
            else return (1 << r) + countNodes(root.left);
        }
        private int depth(TreeNode root){
            int dep = 0;
            while(root != null) {
                dep++;
                root = root.left;
            }
            return dep;
        }
    }
}